package com.mastercard.assets.util;

import java.io.File;
import java.io.FileOutputStream;

import java.io.FileInputStream;
import java.sql.Date;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import javax.crypto.Cipher;

import javax.crypto.KeyGenerator;
import javax.crypto.spec.SecretKeySpec;
import javax.mail.Message;
//import javax.mail.Authenticator;
import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts.upload.FormFile;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import com.mastercard.assets.MasterCardException;
import com.mastercard.assets.jpa.TblAsset;
import com.mastercard.assets.jpa.TblCampania;
import com.mastercard.assets.jpa.TblCuenta;
import com.mastercard.assets.jpa.TblNivel;
import com.mastercard.assets.jpa.TblPaquete;
import com.mastercard.assets.jpa.TblRole;
import com.mastercard.assets.jpa.TblTarea;
import com.mastercard.assets.jpa.TblTipoCuentaPaquete;
import com.mastercard.assets.jpa.TblUsuario;
import com.mastercard.assets.util.languages.MCMessages;
import com.mastercard.assets.web.util.RoleComparator;
import com.mastercard.assets.web.util.to.ManejadorPaquetesDeAsset;
import com.mastercard.assets.web.util.to.UserLogin;
import javax.mail.PasswordAuthentication;
import javax.mail.Transport;
//import com.sun.xml.internal.messaging.saaj.packaging.mime.MessagingException;

public class MCUtil
{
	public static final String CONF_PROPS_FORMS_DIR_PATH = "formas.directorio" ;
	public static final String CONF_PROPS_FORMS_DIR_INSIDE = "formas.directorio.inside" ;
        public static final String CONF_PROPS_BC_DIR_PATH = "bc.directorio" ;
	public static final String CONF_PROPS_BC_DIR_INSIDE = "bc.directorio.inside" ;
        public static final String CONF_PROPS_CONTRATO_DIR_PATH = "contrato.directorio" ;
	public static final String CONF_PROPS_CONTRATO_DIR_INSIDE = "contrato.directorio.inside" ;
        public static final String CONF_PROPS_FOTOS_DIR_PATH = "fotos.directorio" ;
	public static final String CONF_PROPS_FOTOS_DIR_INSIDE = "fotos.directorio.inside" ;
        public static final String CONF_PROPS_BOLETO_DIR_PATH = "boleto.directorio" ;
	public static final String CONF_PROPS_BOLETO_DIR_INSIDE = "boleto.directorio.inside" ;
        public static final String CONF_PROPS_AGENDA_DIR_PATH = "agenda.directorio" ;
	public static final String CONF_PROPS_AGENDA_DIR_INSIDE = "agenda.directorio.inside" ;
        public static final String CONF_PROPS_COTIZACION_DIR_PATH = "cotizacion.directorio" ;
	public static final String CONF_PROPS_COTIZACION_DIR_INSIDE = "cotizacion.directorio.inside" ;
        public static final String CONF_PROPS_MATERIALASSET_DIR_PATH = "materialdeasset.directorio" ;
	public static final String CONF_PROPS_MATERIALASSET_DIR_INSIDE = "materialdeasset.directorio.inside" ;
	
	public static final String FORM_PATH = "/omar/forms/" ;
	public static final File FORM_PATH_FILE = new File( FORM_PATH ) ;
	
	public static final int MASTERCARD_ERROR_CODE_SECURITY_PASSWORD_CIPHER_INITIALIZATION = 10000 ;
	public static final int MASTERCARD_ERROR_CODE_SECURITY_PASSWORD_ENCRYPT_NULL = 10001 ;
	public static final int MASTERCARD_ERROR_CODE_SECURITY_PASSWORD_ENCRYPT_ERROR = 10002 ;
	public static final int MASTERCARD_ERROR_CODE_SECURITY_PASSWORD_DECRYPT_NULL = 10003 ;
	public static final int MASTERCARD_ERROR_CODE_SECURITY_PASSWORD_DECRYPT_ERROR = 10004 ;

	public static final int MASTERCARD_ERROR_CODE_USERLOGIN_USER_MUST_BE_LOGGEDIN = 20000 ;
	public static final int MASTERCARD_ERROR_CODE_USERLOGIN_USER_THERE_IS_NO_EXIST_THAT_ROLE = 20001 ;
	public static final int MASTERCARD_ERROR_CODE_USERLOGIN_COUNTYPE_ERROR_GETTINT_ALL_ACTIVE_COUNT_TYPES = 20002 ;
	public static final int MASTERCARD_ERROR_CODE_USERLOGIN_COUNTYPE_ERROR_GETTINT_ALL_ACTIVE_COUNTS = 20003 ;
	public static final int MASTERCARD_ERROR_CODE_USERLOGIN_COUNTYPE_ERROR_GETTINT_ALL_ACTIVE_SUBCATEGORY = 20004 ;
	public static final int MASTERCARD_ERROR_CODE_USERLOGIN_COUNTYPE_ERROR_GETTINT_ALL_ACTIVE_SEGMENTS = 20005 ;
	public static final int MASTERCARD_ERROR_CODE_USERLOGIN_COUNTYPE_ERROR_GETTINT_ALL_ACTIVE_PRODUCTTYPE = 20006 ;
	public static final int MASTERCARD_ERROR_CODE_USERLOGIN_COUNTYPE_ERROR_GETTINT_ALL_ACTIVE_PRODUCTS = 20007 ;
	public static final int MASTERCARD_ERROR_CODE_USERLOGIN_COUNTYPE_ERROR_GETTINT_ALL_ACTIVE_SERVICES = 20008 ;
	public static final int MASTERCARD_ERROR_CODE_USERLOGIN_COUNTYPE_ERROR_GETTINT_ALL_ACTIVE_AGENCIES = 20009 ;
	public static final int MASTERCARD_ERROR_CODE_USERLOGIN_COUNTYPE_ERROR_GETTINT_ALL_ACTIVE_ROLES = 20010 ;
	public static final int MASTERCARD_ERROR_CODE_USERLOGIN_COUNTYPE_ERROR_GETTINT_ALL_ACTIVE_LEVELS = 20011 ;
	public static final int MASTERCARD_ERROR_CODE_USERLOGIN_COUNTYPE_ERROR_GETTINT_ALL_ACTIVE_ASSETS = 20012 ;
	public static final int MASTERCARD_ERROR_CODE_USERLOGIN_USER_THERE_IS_NO_EXIST_THAT_COUNT = 20013 ;
	public static final int MASTERCARD_ERROR_CODE_USERLOGIN_COUNTYPE_ERROR_GETTINT_ALL_ACTIVE_NOTIFICATIONS = 20014 ;

	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_COUNTTYPE_EMPTY_FIELD_NAME = 30000 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_COUNTTYPE_ERROR = 30001 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_COUNTTYPE_ALREADY_EXIST = 30002 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_COUNTTYPE_CAN_NOT_ERASE = 30003 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_COUNTTYPE_CAN_NOT_UPDATE = 30004 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_COUNT_EMPTY_FIELD_NAME = 30005 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_COUNT_ERROR = 30006 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_COUNT_ALREADY_EXIST = 30007 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_COUNT_CAN_NOT_ERASE = 30008 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_COUNT_CAN_NOT_UPDATE = 30009 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_COUNT_COUNTTYPE_NOT_EXIST = 30010 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_CATEGORY_EMPTY_FIELD_NAME = 30011 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_CATEGORY_ERROR = 30012 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_CATEGORY_ALREADY_EXIST = 30013 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_CATEGORY_CAN_NOT_ERASE = 30014 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_CATEGORY_CAN_NOT_UPDATE = 30015 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_SUBCATEGORY_EMPTY_FIELD_NAME = 30016 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_SUBCATEGORY_ERROR = 30017 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_SUBCATEGORY_ALREADY_EXIST = 30018 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_SUBCATEGORY_CAN_NOT_ERASE = 30019 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_SUBCATEGORY_CAN_NOT_UPDATE = 30020 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_SUBCATEGORY_CATEGORY_NOT_EXIST = 30021 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_SEGMENT_EMPTY_FIELD_NAME = 30022 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_SEGMENT_ERROR = 30023 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_SEGMENT_ALREADY_EXIST = 30024 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_SEGMENT_CAN_NOT_ERASE = 30025 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_SEGMENT_CAN_NOT_UPDATE = 30026 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PRODUCTTYPE_EMPTY_FIELD_NAME = 30027 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PRODUCTTYPE_ERROR = 30028 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PRODUCTTYPE_ALREADY_EXIST = 30029 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PRODUCTTYPE_CAN_NOT_ERASE = 30030 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PRODUCTTYPE_CAN_NOT_UPDATE = 30031 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PRODUCT_EMPTY_FIELD_NAME = 30032 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PRODUCT_ERROR = 30033 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PRODUCT_ALREADY_EXIST = 30034 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PRODUCT_CAN_NOT_ERASE = 30035 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PRODUCT_CAN_NOT_UPDATE = 30036 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PRODUCT_PRODUCTTYPE_NOT_EXIST = 30037 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PRODUCT_SEGMENT_NOT_EXIST = 30038 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_CAMPAIGN_TYPE_EMPTY_FIELD_NAME = 30039 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_CAMPAIGN_TYPE_ERROR = 30040 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_CAMPAIGN_TYPE_ALREADY_EXIST = 30041 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_CAMPAIGN_TYPE_CAN_NOT_ERASE = 30042 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_CAMPAIGN_TYPE_CAN_NOT_UPDATE = 30043 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_AGENCY_EMPTY_FIELD_NAME = 30044 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_AGENCY_ERROR = 30045 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_AGENCY_ALREADY_EXIST = 30046 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_AGENCY_CAN_NOT_ERASE = 30047 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_AGENCY_CAN_NOT_UPDATE = 30048 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_SERVICE_EMPTY_FIELD_NAME = 30049 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_SERVICE_ERROR = 30050 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_SERVICE_ALREADY_EXIST = 30051 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_SERVICE_CAN_NOT_ERASE = 30052 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_SERVICE_CAN_NOT_UPDATE = 30053 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_ROLE_EMPTY_FIELD_NAME = 30054 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_ROLE_ERROR = 30055 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_ROLE_ALREADY_EXIST = 30056 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_ROLE_CAN_NOT_ERASE = 30057 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_ROLE_CAN_NOT_UPDATE = 30058 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_LEVEL_EMPTY_FIELD_NAME = 30059 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_LEVEL_ERROR = 30060 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_LEVEL_ALREADY_EXIST = 30061 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_LEVEL_CAN_NOT_ERASE = 30062 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_LEVEL_CAN_NOT_UPDATE = 30063 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_LEVEL_ROLE_NOT_EXIST = 30064 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_USER_EMPTY_FIELD_NAME = 30065 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_USER_ERROR = 30066 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_USER_ALREADY_EXIST = 30067 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_USER_CAN_NOT_ERASE = 30068 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_USER_CAN_NOT_UPDATE = 30069 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_USER_ROLE_NOT_EXIST = 30070 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_USER_CAN_NOT_ERASE_ROLE_FROM_USER = 30071 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_USER_CAN_NOT_ADD_ROLE_TO_USER = 30072 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_USER_CAN_NOT_ADD_LEVEL_TO_USER = 30073 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_USER_CAN_NOT_ERASE_LEVEL_FROM_USER = 30074 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_ASSET_EMPTY_FIELD_NAME = 30075 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_ASSET_ERROR = 30076 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_ASSET_ALREADY_EXIST = 30077 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_ASSET_CAN_NOT_ERASE = 30078 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_ASSET_CAN_NOT_UPDATE = 30079 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PACKAGE_EMPTY_FIELD_NAME = 30080 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PACKAGE_ERROR = 30081 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PACKAGE_ALREADY_EXIST = 30082 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PACKAGE_CAN_NOT_ERASE = 30083 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PACKAGE_CAN_NOT_UPDATE = 30084 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PACKAGE_NOT_EXIST = 30085 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PACKAGE_COUNT_TYPE_NOT_EXIST = 30085 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PACKAGE_NOT_AVAILABLE = 30086 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_USER_CAN_NOT_ADD_COUNT_TO_USER = 30087 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_USER_CAN_NOT_ERASE_COUNT_FROM_USER = 30088 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_COUNT_REALCOUNTTYPE_NOT_EXIST = 30089 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_REALCOUNTTYPE_ALREADY_EXIST = 30090 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_REALCOUNTTYPE_ERROR = 30091 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_REALCOUNTTYPE_CAN_NOT_ERASE = 30092 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_ASSETTIPO_CAN_NOT_ERASE = 30093 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_PACKAGE_FREE_LESS_THAN_ERASE = 30094 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_NOTIFICATION_EMPTY_FIELD_NAME = 30095 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_NOTIFICATION_ERROR = 30096 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_NOTIFICATION_ALREADY_EXIST = 30097 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_NOTIFICATION_CAN_NOT_ERASE = 30098 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_NOTIFICATION_CAN_NOT_UPDATE = 30099 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_NOTIFICATION_ALERT_NOT_EXIST = 30100 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_NOTIFICATION_ROLE_NOT_EXIST = 30101 ;
	public static final int MASTERCARD_ERROR_CODE_CATALOGUE_NOTIFICATION_LEVEL_NOT_EXIST = 30102 ;
	
	public static final int MASTERCARD_ERROR_CODE_COUNTTYPE_PACKAGEREQUEST_COUNTTYPE_NOT_EXITS = 11000 ;
	public static final int MASTERCARD_ERROR_CODE_COUNTTYPE_PACKAGEREQUEST_COUNTTYPE_ID_NOT_EXITS = 11001 ;

	public static final int MASTERCARD_ERROR_CODE_PACKAGEAUTHORIZE_REQUEST_ID_INVALID = 12000 ;
	public static final int MASTERCARD_ERROR_CODE_PACKAGEAUTHORIZE_REQUEST_ID_NOT_EXIST = 12001 ;
	public static final int MASTERCARD_ERROR_CODE_PACKAGEAUTHORIZE_COUNT_ID_INVALID = 12002 ;
	public static final int MASTERCARD_ERROR_CODE_PACKAGEAUTHORIZE_USER_ID_INVALID = 12003 ;
	public static final int MASTERCARD_ERROR_CODE_PACKAGEAUTHORIZE_COUNT_ID_NOT_EXIST = 12004 ;
	public static final int MASTERCARD_ERROR_CODE_PACKAGEAUTHORIZE_USER_ID_NOT_EXIST = 12005 ;
	
	public static final int MASTERCARD_ERROR_CODE_COUNTTYPE_PACKAGEASIGNED_COUNT_ID_NOT_EXITS = 12000 ;
	
	public static final int MASTERCARD_ERROR_CODE_COUNT_PACKAGEASIGNED_COUNT_ID_NOT_EXITS = 18000 ;
	
	public static final int MASTERCARD_ERROR_CODE_CAMPAIGN_EMTPY_NAME = 13000 ;
	public static final int MASTERCARD_ERROR_CODE_CAMPAIGN_EMTPY_FECHA_INI = 13001 ;
	public static final int MASTERCARD_ERROR_CODE_CAMPAIGN_EMTPY_FECHA_FIN = 13002 ;
	public static final int MASTERCARD_ERROR_CODE_CAMPAIGN_EMTPY_CAMPAIGN_TYPE = 13003 ;
	public static final int MASTERCARD_ERROR_CODE_CAMPAIGN_NO_USER_IN_CHARGE = 13004 ;
	public static final int MASTERCARD_ERROR_CODE_CAMPAIGN_NAME_ALREADY_EXIST = 13005 ;
	public static final int MASTERCARD_ERROR_CODE_CAMPAIGN_NO_PRODUCT = 13006 ;
	public static final int MASTERCARD_ERROR_CODE_CAMPAIGN_NO_USER_TO_SETUP = 13007 ;
	public static final int MASTERCARD_ERROR_CODE_CAMPAIGN_NO_PACKAGES = 13008 ;
	public static final int MASTERCARD_ERROR_CODE_CAMPAIGN_USER_INVALID = 13009 ;
	public static final int MASTERCARD_ERROR_CODE_CAMPAIGN_USER_NOT_EXIST = 13010 ;
	public static final int MASTERCARD_ERROR_CODE_CAMPAIGN_ID_INVALID = 13011 ;
	public static final int MASTERCARD_ERROR_CODE_CAMPAIGN_CHANGE_STATUS_ERROR = 13012 ;
	public static final int MASTERCARD_ERROR_CODE_CAMPAIGN_ID_NOT_EXIST = 13013 ;
	public static final int MASTERCARD_ERROR_CODE_CAMPAIGN_COUNT_ID_INVALID = 13014 ;
	public static final int MASTERCARD_ERROR_CODE_CAMPAIGN_COUNT_ID_NOT_EXIST = 13015 ;

	public static final int MASTERCARD_ERROR_CODE_FORMS_ERROR_GETTING_ALL_ACTIVE_FORMS = 14000 ;
	public static final int MASTERCARD_ERROR_CODE_FORMS_ERROR_NAME_EMPTY = 14001 ;
	public static final int MASTERCARD_ERROR_CODE_FORMS_ERROR_EXITS_EMPTY = 14002 ;
	public static final int MASTERCARD_ERROR_CODE_FORMS_ERROR_EXITS_ALL_EMPTY = 14003 ;

	public static final int MASTERCARD_ERROR_CODE_ALERTS_ERROR_GETTING_ALL_ACTIVE_FORMS = 15000 ;
	public static final int MASTERCARD_ERROR_CODE_ALERTS_ERROR_NAME_EMPTY = 15001 ;
	public static final int MASTERCARD_ERROR_CODE_ALERTS_ERROR_EXITS_EMPTY = 15002 ;
	public static final int MASTERCARD_ERROR_CODE_ALERTS_ERROR_EXITS_ALL_EMPTY = 15003 ;

	public static final int MASTERCARD_ERROR_CODE_FLOWS_ERROR_GETTING_ALL_ACTIVE_FORMS = 16000 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_ERROR_NAME_EMPTY = 16001 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_ERROR_EXITS_EMPTY = 16002 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_ERROR_EXITS_ALL_EMPTY = 16003 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_ERROR_ADDING_FLOW = 16004 ;

	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_GETTING_ALL_ACTIVE_FORMS = 16000 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_ROLE_WRONG = 16001 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_FLOW_WRONG = 16002 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_FORM_WRONG = 16003 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_LEVEL_WRONG = 16007 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_ROLE_NOT_EXIST = 16004 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_FLOW_NOT_EXIST = 16005 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_FORM_NOT_EXIST = 16006 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_LEVEL_NOT_EXIST = 16006 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_REMOVE_WORK = 16007 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_WORK_WRONG = 16008 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_WORK_NOT_EXIST = 16009 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_EXIT_WRONG = 16010 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_EXIT_NOT_EXIST = 16011 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_UPDATE_EXIT = 16012 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_ALERT_WRONG = 16013 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_ALERT_NOT_EXIST = 16014 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_FORM_ALERT_WRONG = 16015 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_FORM_ALERT_NOT_EXIST = 16016 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_FORM_ALARM_WRONG = 16017 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_FORM_ALARM_NOT_EXIST = 16017 ;
	public static final int MASTERCARD_ERROR_CODE_WORKS_ERROR_CHANGE_FIRST_WORK_ERROR = 16018 ;
	
	public static final int MASTERCARD_ERROR_CODE_PREIMPLEMENTATION_ERROR_FLOW_EMPTY = 17000 ;
	public static final int MASTERCARD_ERROR_CODE_PREIMPLEMENTATION_ERROR_ASSETS_EMPTY = 17001 ;
	public static final int MASTERCARD_ERROR_CODE_PREIMPLEMENTATION_ERROR_ASSETS_WRONG = 17002 ;
	public static final int MASTERCARD_ERROR_CODE_PREIMPLEMENTATION_ERROR_THROW_EXIT = 17003 ;
	public static final int MASTERCARD_ERROR_CODE_PREIMPLEMENTATION_ERROR_FLOW_WITHOUT_FIRST_WORK = 17004 ;
	public static final int MASTERCARD_ERROR_CODE_PREIMPLEMENTATION_ERROR_FLOW_WITHOUT_WORKS = 17005 ;
	public static final int MASTERCARD_ERROR_CODE_PREIMPLEMENTATION_ERROR_STOP_PREIM = 17006 ;
	
	public static final int MASTERCARD_ERROR_CODE_IMPLEMENTATION_ERROR_FLOW_EMPTY = 19000 ;
	public static final int MASTERCARD_ERROR_CODE_IMPLEMENTATION_ERROR_ASSETS_EMPTY = 19001 ;
	public static final int MASTERCARD_ERROR_CODE_IMPLEMENTATION_ERROR_ASSETS_WRONG = 19002 ;
	public static final int MASTERCARD_ERROR_CODE_IMPLEMENTATION_ERROR_THROW_EXIT = 19003 ;
	public static final int MASTERCARD_ERROR_CODE_IMPLEMENTATION_ERROR_FLOW_WITHOUT_FIRST_WORK = 19004 ;
	public static final int MASTERCARD_ERROR_CODE_IMPLEMENTATION_ERROR_FLOW_WITHOUT_WORKS = 19005 ;
	public static final int MASTERCARD_ERROR_CODE_IMPLEMENTATION_ERROR_CAMPAIGN_EMPTY = 19006 ;
	public static final int MASTERCARD_ERROR_CODE_IMPLEMENTATION_ERROR_ASSET_WITHOUT_FLOW = 19007 ;

	public static final int MASTERCARD_ERROR_CODE_NOTIFICATION_COUNT_TYPE_NOT_EXIST = 20000 ;
	public static final int MASTERCARD_ERROR_CODE_NOTIFICATION_ERROR = 20001 ;

	public static final int MASTERCARD_ERROR_CODE_FLOWS_WORK_FLOW_NOT_EXITS = 31000 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_WORK_FLOW_WITHOUT_WORK = 31001 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_WORK_FLOW_ALREADY_EXECUTED = 31002 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_WORK_FLOW_WORK_UNACTIVATED = 31003 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_WORK_FLOW_WORK_WITHOUT_FORM = 31004 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_WORK_FLOW_WORK_FORM_UNACTIVATED = 31005 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_WORK_FLOW_WORK_FORM_WITHOUT_INIT_CLASS = 31006 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_WORK_FLOW_WORK_FORM_WITHOUT_POST_CLASS = 31007 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_WORK_FLOW_WORK_FORM_ERROR_LOADING_INIT_CLASS = 31008 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_WORK_FLOW_WORK_FORM_ERROR_LOADING_PREVIOUS_CLASS = 31009 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_WORK_FLOW_WORK_FORM_ERROR_LOADING_POST_CLASS = 31010 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_WORK_FLOW_ERROR_PROCESSING_FORM_DATA = 31011 ;
	
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_CLASS_NOT_EXIST = 32000 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_ERROR = 32001 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_CVE_NOT_EXIST = 32002 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_CVE_WRONG = 32003 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_CVE_USER_NOT_EXIST = 32004 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_CVE_USER_WRONG = 32005 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_EXIT_NOT_EXIST_IN_FORM = 32006 ;
	
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_PREIMPLEMENTATION_NO_SERVICE_SELECTED = 35000 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_PREIMPLEMENTATION_SERVICES_NOT_EQUAL_COMENTS = 35001 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_PREIMPLEMENTATION_SERVICE_NOT_EXIST = 35002 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_PREIMPLEMENTATION_SERVICE_NOT_ACTIVE = 35003 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_PREIMPLEMENTATION_ERROR = 35004 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_PREIMPLEMENTATION_NO_FILE_DATA_EXIST = 35005 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_PREIMPLEMENTATION_NO_FILE_NAME_EXIST = 35006 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_PREIMPLEMENTATION_ERROR_SAVING_FILE = 35007 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_PREIMPLEMENTATION_NO_COTIZACION_EXIST = 35008 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_PREIMPLEMENTATION_ERROR_OBTAINING_PATH = 35009 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_PREIMPLEMENTATION_FORM_FILE_NO_EXIST = 35010 ;
	
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_CAMPAIGN_NO_FILE_EXIST = 36000 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_CAMPAIGN_ERROR_SAVING_FILES = 36001 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_CAMPAIGN_ERROR_EXECUTION_NOT_EXIST = 36002 ;
	public static final int MASTERCARD_ERROR_CODE_FLOWS_PROCESS_CAMPAIGN_ERROR_PROCESING_SCREEN_2_REJECT = 36003 ;
	
	public static final int MASTERCARD_ERROR_CODE_BACKUP_ERROR = 33000 ;
	
	public static final int MASTERCARD_ERROR_CODE_SEND_MAIL = 34000 ;
	
	public static final MCMessages messages = new MCMessages( "com.mastercard.assets.util.languages.Messages" ) ;
	
	private static final String ENCRYPT_DECRYPT_KEY = "jA3.%k2$sS68@#al" ;
	
	private static Cipher encryptPasswordCipher = null ;
	private static Cipher decryptPasswordCipher = null ;
	
	// identificadores de catalogos
	public static final int CATALOGO_ID_TIPO_CUENTA = 1 ;
	public static final int CATALOGO_ID_CUENTA = 2 ;
	public static final int CATALOGO_ID_CATEGORY = 3 ;
	public static final int CATALOGO_ID_SUBCATEGORY = 4 ;
	public static final int CATALOGO_ID_SEGMENTO = 5 ;
	public static final int CATALOGO_ID_PRODUCT_TYPE = 6 ;
	public static final int CATALOGO_ID_PRODUCT = 7 ;
	public static final int CATALOGO_ID_CAMPAIGN_TYPE = 8 ;
	public static final int CATALOGO_ID_AGENCY = 9 ;
	public static final int CATALOGO_ID_SERVICE = 10 ;
	public static final int CATALOGO_ID_ROLE = 11 ;
	public static final int CATALOGO_ID_LEVEL = 12 ;
	public static final int CATALOGO_ID_USUARIOS = 13 ;
	public static final int CATALOGO_ID_TIPO_CUENTA_REAL = 14 ;
        public static final int CATALOGO_ID_BPS = 15 ;
        public static final int CATALOGO_ID_PAISES = 16 ;
        public static final int CATALOGO_ID_FLUJOS_AUT = 17 ;
        
	///////////////
	
	public static String WEB_INF_DIR = null ;
	public static String FORMAS_DIR = null ;
	public static String BC_DIR = null ;
        public static String CONTRATO_DIR = null ;
        public static String FOTOS_DIR = null ;
        public static String BOLETO_DIR = null ;
        public static String AGENDA_DIR = null ;
        public static String COTIZACION_DIR = null ;
        public static String MATERIALASSET_DIR = null ;
	public static final Properties SYSTEM_PROPERTIES = new Properties( ) ;
	
	public static RoleComparator roleComparator = new RoleComparator( ) ;
	
	public static byte[ ] getKeyInBytes( )
	{
		return ENCRYPT_DECRYPT_KEY.getBytes( ) ;
	}
	
	public static void intiPasswordSecurity( )
		throws
			MasterCardException
	{

		// en caso de que no sea null
		if( encryptPasswordCipher != null && decryptPasswordCipher != null )
			return ;
		
		try
		{
			KeyGenerator kgen = KeyGenerator.getInstance( "AES" ) ;
			
			kgen.init(128); // 192 and 256 bits may not be available
	
			// Generate the secret key specs.
			byte[ ] raw = MCUtil.getKeyInBytes( ) ;
			
			SecretKeySpec skeySpec = new SecretKeySpec( raw , "AES" ) ;
			encryptPasswordCipher = Cipher.getInstance( "AES" ) ;
			encryptPasswordCipher.init( Cipher.ENCRYPT_MODE , skeySpec ) ;
			
			decryptPasswordCipher = Cipher.getInstance( "AES" ) ;
			decryptPasswordCipher.init( Cipher.DECRYPT_MODE , skeySpec ) ;
		}catch( Exception e )
		{
			e.printStackTrace( ) ;
			throw new MasterCardException( 
					messages.getString( "com.mastercard.assets.web.errors.util.initPasswordSecurity" ) , 
					MCUtil.MASTERCARD_ERROR_CODE_SECURITY_PASSWORD_CIPHER_INITIALIZATION , 
					e ) ;
		}
	}
	
	public static String encryptPassword( String clearPass )
		throws
			MasterCardException
	{
		// en caso de que este vacio
		if( encryptPasswordCipher == null )
			throw new MasterCardException( 
					MCUtil.messages.getString( "com.mastercard.assets.web.errors.util.PasswordEncryptNull" ) ,
					MCUtil.MASTERCARD_ERROR_CODE_SECURITY_PASSWORD_ENCRYPT_NULL , null ) ;
		
		// intenta encriptar
		try
		{
			byte[ ] cryptedPass = encryptPasswordCipher.doFinal( clearPass.getBytes( ) ) ;
			
			BASE64Encoder enc = new BASE64Encoder( ) ;
			return enc.encode( cryptedPass ) ;
		}catch( Exception e )
		{
			throw new MasterCardException( 
					MCUtil.messages.getString( "com.mastercard.assets.web.errors.util.PasswordEncryptError" , e.getMessage( ) ) ,
					MCUtil.MASTERCARD_ERROR_CODE_SECURITY_PASSWORD_ENCRYPT_ERROR , e ) ;
		}
	}
	
	public static String decryptPassword( String clearPass )
		throws
			MasterCardException
	{
		// en caso de que este vacio
		if( decryptPasswordCipher == null )
			throw new MasterCardException( 
					MCUtil.messages.getString( "com.mastercard.assets.web.errors.util.PasswordDecryptNull" ) ,
					MCUtil.MASTERCARD_ERROR_CODE_SECURITY_PASSWORD_DECRYPT_NULL , null ) ;
		
		// intenta encriptar
		try
		{
			
			BASE64Decoder enc = new BASE64Decoder( ) ;
			
			byte[ ] cryptedPass = decryptPasswordCipher.doFinal( enc.decodeBuffer( clearPass ) ) ;
			
			return new String( cryptedPass ) ;
		}catch( Exception e )
		{
			throw new MasterCardException( 
					MCUtil.messages.getString( "com.mastercard.assets.web.errors.util.PasswordDecryptError" , e.getMessage( ) ) ,
					MCUtil.MASTERCARD_ERROR_CODE_SECURITY_PASSWORD_DECRYPT_ERROR , e ) ;
		}
	}
	
	public static boolean isLoggedIn( HttpServletRequest request )
	{
		HttpSession session = request.getSession( ) ;
		
		// en caos de null
		if( session == null )
			return false ;
		
		// toma el userLogin
		UserLogin user = ( UserLogin ) session.getAttribute( "UserLogin" ) ;
		
		// en caso de null
		if( user == null )
			return false ;
		
		// regresa lo que user
		return user.isLoggedIn( ) ;
		
	}
	
	public static String formatDate( Date date , String format )
	{
		if( date == null || format == null )
			return "" ;
		
		try
		{
			SimpleDateFormat df = new SimpleDateFormat( format ) ;
			return df.format( date ) ;
		}catch( Exception e )
		{
			e.printStackTrace( ) ;
			return "" ;
		}
	}
	
	public static String formatDate( java.util.Date date , String format )
	{
		if( date == null || format == null )
			return "" ;
		
		try
		{
			SimpleDateFormat df = new SimpleDateFormat( format ) ;
			return df.format( date ) ;
		}catch( Exception e )
		{
			return "" ;
		}
	}
	
	public static String formatTimestamp( Timestamp date , String format )
	{
		if( date == null || format == null )
			return "" ;
		
		try
		{
			SimpleDateFormat df = new SimpleDateFormat( format ) ;
			return df.format( date ) ;
		}catch( Exception e )
		{
			return "" ;
		}
	}
	
	public static void updatePackageManager( List< TblPaquete > packages , ManejadorPaquetesDeAsset manager )
	{
		// en caso de null
		if( manager == null )
			return ;
		
		// resetea
//		manager.reset( ) ;
		
//		System.out.println( "!@@@@@@@@@@@ " + packages.size( ) ) ;
		
		// en caso de package en null o vacio
		if( packages == null || packages.size( ) == 0 )
		{
			return ;
		}
		
		// recorre los packages
		for( TblPaquete paquete : packages )
		{
			if( paquete.getStatus( ) == 0 )
				continue ;
			
//			System.out.println( "Paquete: " + paquete.getCvePaquete( ) ) ;
			// verifica que tipo de paquete es
			// obtiene los datos
			int tipoHabitacion = paquete.getHabitacion( ) ;
			int fondeadoA = paquete.getFondeado( ) ;
			int facturadoA = paquete.getFacturadoA( ) ;
			int bandera = paquete.getBandera( ) ;
			
			
//			System.out.println( "Paquete: " + tipoHabitacion + " - " + fondeadoA + " - " + facturadoA + " - " + paquete.getStatus( ) ) ;
			
			// en caso de que sea SLL
			if( tipoHabitacion == 1 && fondeadoA == 1 && facturadoA == 1 )
			{
				manager.addSLL( ) ;
				
				if( bandera == 1 )
					manager.addByAsignToCountTypeSLL( ) ;
				if( bandera == 2 )
					manager.addAsignedToCountTypeSLL( ) ;
				if( bandera == 3 )
					manager.addRejectedToCountTypeSLL( ) ;
				
				List< TblTipoCuentaPaquete > tipoCuentasPaquete = paquete.getTblTipoCuentaPaquetes( ) ;
				
				System.out.println( "Tipo paquete: " + paquete.getCvePaquete( ) + "-" + tipoHabitacion + "-" + fondeadoA + "-" + facturadoA + "-" + bandera + ": " + tipoCuentasPaquete.size( ) ) ;
				
				// recorre
				for( TblTipoCuentaPaquete tcp : tipoCuentasPaquete )
				{
					if( tcp.getStatus( ) == 0 )
						continue ;
					
					// bandera
					int banderaTCP = tcp.getBandera( ) ;
					
					System.out.println( "\tBanderaTCP: " + banderaTCP ) ;
					
					if( banderaTCP == 1 )
						manager.addNoAsignedToCountSLL( ) ;
					if( banderaTCP == 2 )
						manager.addInProccesOfAuthInCountSLL( ) ;
					if( banderaTCP == 3 )
						manager.addAsignedToCountSLL( ) ;
				}
				
			}
			
			// en caso de que sea SLR
			if( tipoHabitacion == 1 && fondeadoA == 1 && facturadoA == 2 )
			{
				manager.addSLR( ) ;
				
				if( bandera == 1 )
					manager.addByAsignToCountTypeSLR( ) ;
				if( bandera == 2 )
					manager.addAsignedToCountTypeSLR( ) ;
				if( bandera == 3 )
					manager.addRejectedToCountTypeSLR( ) ;
				
				List< TblTipoCuentaPaquete > tipoCuentasPaquete = paquete.getTblTipoCuentaPaquetes( ) ;
				
				// recorre
				for( TblTipoCuentaPaquete tcp : tipoCuentasPaquete )
				{
					if( tcp.getStatus( ) == 0 )
						continue ;
					
					// bandera
					int banderaTCP = tcp.getBandera( ) ;
					
					if( banderaTCP == 1 )
						manager.addNoAsignedToCountSLR( ) ;
					if( banderaTCP == 2 )
						manager.addInProccesOfAuthInCountSLR( ) ;
					if( banderaTCP == 3 )
						manager.addAsignedToCountSLR( ) ;
				}
				
			}
			
			// en caso de que sea DLL
			if( tipoHabitacion == 2 && fondeadoA == 1 && facturadoA == 1 )
			{
				manager.addDLL( ) ;
				
				if( bandera == 1 )
					manager.addByAsignToCountTypeDLL( ) ;
				if( bandera == 2 )
					manager.addAsignedToCountTypeDLL( ) ;
				if( bandera == 3 )
					manager.addRejectedToCountTypeDLL( ) ;
				
				List< TblTipoCuentaPaquete > tipoCuentasPaquete = paquete.getTblTipoCuentaPaquetes( ) ;
				
				// recorre
				for( TblTipoCuentaPaquete tcp : tipoCuentasPaquete )
				{
					if( tcp.getStatus( ) == 0 )
						continue ;
					
					// bandera
					int banderaTCP = tcp.getBandera( ) ;
					
					if( banderaTCP == 1 )
						manager.addNoAsignedToCountDLL( ) ;
					if( banderaTCP == 2 )
						manager.addInProccesOfAuthInCountDLL( ) ;
					if( banderaTCP == 3 )
						manager.addAsignedToCountDLL( ) ;
				}
				
			}
			
			// en caso de que sea DLR
			if( tipoHabitacion == 2 && fondeadoA == 1 && facturadoA == 2 )
			{
				manager.addDLR( ) ;
				
				if( bandera == 1 )
					manager.addByAsignToCountTypeDLR( ) ;
				if( bandera == 2 )
					manager.addAsignedToCountTypeDLR( ) ;
				if( bandera == 3 )
					manager.addRejectedToCountTypeDLR( ) ;
				
				List< TblTipoCuentaPaquete > tipoCuentasPaquete = paquete.getTblTipoCuentaPaquetes( ) ;
				
				// recorre
				for( TblTipoCuentaPaquete tcp : tipoCuentasPaquete )
				{
					if( tcp.getStatus( ) == 0 )
						continue ;
					
					// bandera
					int banderaTCP = tcp.getBandera( ) ;
					
					if( banderaTCP == 1 )
						manager.addNoAsignedToCountDLR( ) ;
					if( banderaTCP == 2 )
						manager.addInProccesOfAuthInCountDLR( ) ;
					if( banderaTCP == 3 )
						manager.addAsignedToCountDLR( ) ;
				}
				
			}

			
			// en caso de que sea SRL
			if( tipoHabitacion == 1 && fondeadoA == 2 && facturadoA == 1 )
			{
				manager.addSRL( ) ;
				
				if( bandera == 1 )
					manager.addByAsignToCountTypeSRL( ) ;
				if( bandera == 2 )
					manager.addAsignedToCountTypeSRL( ) ;
				if( bandera == 3 )
					manager.addRejectedToCountTypeSRL( ) ;
				
				List< TblTipoCuentaPaquete > tipoCuentasPaquete = paquete.getTblTipoCuentaPaquetes( ) ;
				
				// recorre
				for( TblTipoCuentaPaquete tcp : tipoCuentasPaquete )
				{
					if( tcp.getStatus( ) == 0 )
						continue ;
					
					// bandera
					int banderaTCP = tcp.getBandera( ) ;
					
					if( banderaTCP == 1 )
						manager.addNoAsignedToCountSRL( ) ;
					if( banderaTCP == 2 )
						manager.addInProccesOfAuthInCountSRL( ) ;
					if( banderaTCP == 3 )
						manager.addAsignedToCountSRL( ) ;
				}
				
			}
			
			// en caso de que sea SRR
			if( tipoHabitacion == 1 && fondeadoA == 2 && facturadoA == 2 )
			{
				manager.addSRR( ) ;
				
				if( bandera == 1 )
					manager.addByAsignToCountTypeSRR( ) ;
				if( bandera == 2 )
					manager.addAsignedToCountTypeSRR( ) ;
				if( bandera == 3 )
					manager.addRejectedToCountTypeSRR( ) ;
				
				List< TblTipoCuentaPaquete > tipoCuentasPaquete = paquete.getTblTipoCuentaPaquetes( ) ;
				
				// recorre
				for( TblTipoCuentaPaquete tcp : tipoCuentasPaquete )
				{
					if( tcp.getStatus( ) == 0 )
						continue ;
					
					// bandera
					int banderaTCP = tcp.getBandera( ) ;
					
					if( banderaTCP == 1 )
						manager.addNoAsignedToCountSRR( ) ;
					if( banderaTCP == 2 )
						manager.addInProccesOfAuthInCountSRR( ) ;
					if( banderaTCP == 3 )
						manager.addAsignedToCountSRR( ) ;
				}
				
			}
			
			// en caso de que sea DRL
			if( tipoHabitacion == 2 && fondeadoA == 2 && facturadoA == 1 )
			{
				manager.addDRL( ) ;
				
				if( bandera == 1 )
					manager.addByAsignToCountTypeDRL( ) ;
				if( bandera == 2 )
					manager.addAsignedToCountTypeDRL( ) ;
				if( bandera == 3 )
					manager.addRejectedToCountTypeDRL( ) ;
				
				List< TblTipoCuentaPaquete > tipoCuentasPaquete = paquete.getTblTipoCuentaPaquetes( ) ;
				
				// recorre
				for( TblTipoCuentaPaquete tcp : tipoCuentasPaquete )
				{
					if( tcp.getStatus( ) == 0 )
						continue ;
					
					// bandera
					int banderaTCP = tcp.getBandera( ) ;
					
					if( banderaTCP == 1 )
						manager.addNoAsignedToCountDRL( ) ;
					if( banderaTCP == 2 )
						manager.addInProccesOfAuthInCountDRL( ) ;
					if( banderaTCP == 3 )
						manager.addAsignedToCountDRL( ) ;
				}
				
			}
			
			// en caso de que sea DRR
			if( tipoHabitacion == 2 && fondeadoA == 2 && facturadoA == 2 )
			{
				manager.addDRR( ) ;
				
				if( bandera == 1 )
					manager.addByAsignToCountTypeDRR( ) ;
				if( bandera == 2 )
					manager.addAsignedToCountTypeDRR( ) ;
				if( bandera == 3 )
					manager.addRejectedToCountTypeDRR( ) ;
				
				List< TblTipoCuentaPaquete > tipoCuentasPaquete = paquete.getTblTipoCuentaPaquetes( ) ;
				
				// recorre
				for( TblTipoCuentaPaquete tcp : tipoCuentasPaquete )
				{
					if( tcp.getStatus( ) == 0 )
						continue ;
					
					// bandera
					int banderaTCP = tcp.getBandera( ) ;
					
					if( banderaTCP == 1 )
						manager.addNoAsignedToCountDRR( ) ;
					if( banderaTCP == 2 )
						manager.addInProccesOfAuthInCountDRR( ) ;
					if( banderaTCP == 3 )
						manager.addAsignedToCountDRR( ) ;
				}
				
			}
		}
		
	}
	
	public static String getShortString( String s , int length )
	{
		if( length < 1 )
			return s ;
		
		int sLength = s.length( ) ;
		
		if( sLength > length )
		{
			return s.substring( 0 , length - 3 ) + "..." ;
		}
		
		// en caso de que sea igual o menor
		return s ;
	}
	
	public static String getFormaJSPFileName( int cveForma )
	{
		// directorio de formas
		File dir = new File( MCUtil.getFormsDir( ) ) ;
		
		// toma todos los nombres
		String[ ] files = dir.list( ) ;
		
		String base = "Forma-" + cveForma + "_" ;
		
		// recorre
		for( String file : files )
			// en caso de que empieze por lo correcto
			if( file.startsWith( base ) )
				return file ;
		
		return null ;
	}
	
	public static String getFormaJSPFilePath( int cveForma )
	{
		String fileName = getFormaJSPFileName( cveForma ) ;
		
		if( fileName == null )
			return null ;
		
		return MCUtil.getFormsDir( ) + fileName ;
	}
	
	public static boolean removeAllFormFiles( int cveForma )
	{
		// directorio de formas
		File dir = new File( MCUtil.getFormsDir( ) ) ;
		
		if( ! dir.exists( ) )
		{
			dir.mkdirs( ) ;
			
			return true ;
		}
		
		// toma todos los nombres
		File[ ] files = dir.listFiles( ) ;
		
		String base = "Forma-" + cveForma + "_" ;
		
		// recorre
		for( File file : files )
			// en caso de que empieze por lo correcto
			if( file.getName( ).startsWith( base ) )
				file.delete( ) ;
		
		return true ;
	}
        
        public static boolean removeAllBoletosFiles( int cveBoleto )
	{
		// directorio de boletos
		File dir = new File( MCUtil.getBoletoDir( ) ) ;
		
		if( ! dir.exists( ) )
		{
			dir.mkdirs( ) ;
			
			return true ;
		}
		
		// toma todos los nombres
		File[ ] files = dir.listFiles( ) ;
		
		String base = "Boleto-" + cveBoleto + "_" ;
		
		// recorre
		for( File file : files )
			// en caso de que empieze por lo correcto
			if( file.getName( ).startsWith( base ) )
				file.delete( ) ;
		
		return true ;
	}        
                
        public static boolean removeAllAgendasFiles( int cveAgenda )
	{
		// directorio de boletos
		File dir = new File( MCUtil.getAgendaDir( ) ) ;
		
		if( ! dir.exists( ) )
		{
			dir.mkdirs( ) ;
			
			return true ;
		}
		
		// toma todos los nombres
		File[ ] files = dir.listFiles( ) ;
		
		String base = "Agenda-" + cveAgenda + "_" ;
		
		// recorre
		for( File file : files )
			// en caso de que empieze por lo correcto
			if( file.getName( ).startsWith( base ) )
				file.delete( ) ;
		
		return true ;
	}
        
        public static boolean removeAllCotizacionFiles( int cveCotizacion )
	{
		// directorio de cotizacion
		File dir = new File( MCUtil.getCotizacionDir( ) ) ;
		
		if( ! dir.exists( ) )
		{
			dir.mkdirs( ) ;
			
			return true ;
		}
		
		// toma todos los nombres
		File[ ] files = dir.listFiles( ) ;
		
		String base = "Cotizacion-" + cveCotizacion + "_" ;
		
		// recorre
		for( File file : files )
			// en caso de que empieze por lo correcto
			if( file.getName( ).startsWith( base ) )
				file.delete( ) ;
		
		return true ;
	}
	
	public static String extractFormaFileName( int cveForma , String fileName )
	{
		return "Forma-" + cveForma + "_" + fileName ;
	}
        
        public static String extractBCFileName( int cveCampana , String fileName )
	{
		return "BusinessCase-" + cveCampana + "_" + fileName ;
	}
        
        public static String extractContratoFileName( int cveCampana , String fileName )
	{
		return "Contrato-" + cveCampana + "_" + fileName ;
	}
        
        public static String extractBoletoFileName( int cveG , String fileName )
	{
		return "Boleto-" + cveG + "_" +  fileName ;
	}
        
        public static String extractAgendaFileName( int cveG , String fileName )
	{
		return "Agenda-" + cveG + "_" +  fileName ;
	}
        
        public static String extractCotizacionFileName( int cveG , String fileName )
	{
		return "Cotizacion-" + cveG + "_" +  fileName ;
	}
        
        public static String extractMaterialAssetFileName( int cveG , String fileName , String index )
	{
		return "MA-" + cveG + "-" + index + "_" +  fileName ;
	}
        
        public static String extractMaterialFileName( int cveMaterial , String fileName )
        {
            return "Material-" + cveMaterial + "_" + fileName ;
        }
	
	public static boolean isUserInLevelForPreimplementations( TblUsuario user , TblTarea tarea )
	{
		// en caos de que usuario sea null
		if( user == null )
			return false ;
		
		TblNivel nivel = tarea.getTblNivel( ) ;
		
		// en caos de que nivel sea null
		if( nivel == null )
		{
			// revisa que pertenezca al rol
			TblRole role = tarea.getTblRole( ) ;
			int cveRole = role.getCveRole( ) ;
			
			// roles de usuario
			List< TblRole > roles = user.getTblRoles( ) ;
			
			boolean hasRole = false ;
			
			// recorre los roles
			for( TblRole r : roles )
			{
				// en caso de que no este activo
				if( r.getStatus( ) == 0 )
					// siguiente
					continue ;
				
				// revisa role
				// si coincide
				if( cveRole == r.getCveRole( ) )
				{
					// cambia bandera
					hasRole = true ;
					
					// quiebra ciclo
					break ;
				}
			}
			
			System.out.println( "Pertenece al rol? " + hasRole ) ;
			
			// regresa bandera
			return hasRole ;
		}
		
		// en caso de que no sea null
		// revisa niveles
		
		// toma los niveles
		List< TblNivel > niveles = user.getTblNivels( ) ;
		
		int cveNivel = nivel.getCveNivel( ) ;
		
		// recorre
		for( TblNivel n : niveles )
		{
			// revisa
			if( n.getCveNivel( ) == cveNivel )
				return true ;
		}
		
		// en caso contrario
		return false ;
	}
	//public
        public static String getMaterialdir ( )
        {
            String CONF_PROPS_FORMS_DIR_PATH = "materiales.directorio" ;
            String CONF_PROPS_FORMS_DIR_INSIDE = "materiales.directorio.inside" ;
            String materialsDir = getConfProperty( CONF_PROPS_FORMS_DIR_PATH ) ;
            String materialsSta = getConfProperty( CONF_PROPS_FORMS_DIR_INSIDE ) ;
            
            // en caso de ser null
		if( materialsSta == null || materialsSta.equals( "2" ) )
		{
			File f = new File( materialsDir ) ;
			return f.getAbsolutePath( ) ;
//			return formsDir ;
		}
		else
		{
			File f = new File( WEB_INF_DIR , materialsDir ) ;
			return f.getAbsolutePath( ) ;
//			return WEB_INF_DIR + System.getProperty( "file.separator" ) + formsDir ;
		}            
        }
	public static String getFormsDir( )
	{
		String formsDir = getConfProperty( CONF_PROPS_FORMS_DIR_PATH ) ;
		String formsSta = getConfProperty( CONF_PROPS_FORMS_DIR_INSIDE ) ;
		
		// en caso de ser null
		if( formsSta == null || formsSta.equals( "2" ) )
		{
			File f = new File( formsDir ) ;
			return f.getAbsolutePath( ) ;
//			return formsDir ;
		}
		else
		{
			File f = new File( WEB_INF_DIR.replaceAll( "build\\\\web" , "WebContent" ) , formsDir ) ;
			return f.getAbsolutePath( ) ;
//			return WEB_INF_DIR + System.getProperty( "file.separator" ) + formsDir ;
		}
	}
        
        public static String getBCDir( )
	{
		String bcDir = getConfProperty( CONF_PROPS_BC_DIR_PATH ) ;
		String bcSta = getConfProperty( CONF_PROPS_BC_DIR_INSIDE ) ;
		
		// en caso de ser null
		if( bcSta == null || bcSta.equals( "2" ) )
		{
			File f = new File( bcDir ) ;
			return f.getAbsolutePath( ) ;
//			return formsDir ;
		}
		else
		{			
                        File f = new File( WEB_INF_DIR.replaceAll( "build\\\\web" , "WebContent" ) , bcDir ) ;
			return f.getAbsolutePath( ) ;
//                        return "/WEB-INF/" + bcDir;
//			return WEB_INF_DIR + System.getProperty( "file.separator" ) + formsDir ;
		}
	}
        
        public static String getContratoDir( )
	{
		String contratoDir = getConfProperty( CONF_PROPS_CONTRATO_DIR_PATH ) ;
		String contratoSta = getConfProperty( CONF_PROPS_CONTRATO_DIR_INSIDE ) ;
		
		// en caso de ser null
		if( contratoSta == null || contratoSta.equals( "2" ) )
		{
			File f = new File( contratoDir ) ;
			return f.getAbsolutePath( ) ;
//			return formsDir ;
		}
		else
		{			
                        File f = new File( WEB_INF_DIR.replaceAll( "build\\\\web" , "WebContent" ) , contratoDir ) ;
			return f.getAbsolutePath( ) ;
//                        return "/WEB-INF/" + bcDir;
//			return WEB_INF_DIR + System.getProperty( "file.separator" ) + formsDir ;
		}
	}
        
        public static String getFotoDir( )
	{
		String fotoDir = getConfProperty( CONF_PROPS_FOTOS_DIR_PATH ) ;
		String fotoSta = getConfProperty( CONF_PROPS_FOTOS_DIR_INSIDE ) ;
		
		// en caso de ser null
		if( fotoSta == null || fotoSta.equals( "2" ) )
		{
			File f = new File( fotoDir ) ;
			return f.getAbsolutePath( ) ;
//			return formsDir ;
		}
		else
		{			
                        File f = new File( WEB_INF_DIR.replaceAll( "build\\\\web" , "WebContent" ) , fotoDir ) ;
			return f.getAbsolutePath( ) ;
//                        return "/WEB-INF/" + bcDir;
//			return WEB_INF_DIR + System.getProperty( "file.separator" ) + formsDir ;
		}
	}
        
        public static String getBoletoDir( )
	{
		String boletoDir = getConfProperty( CONF_PROPS_BOLETO_DIR_PATH ) ;
		String boletoSta = getConfProperty( CONF_PROPS_BOLETO_DIR_INSIDE ) ;
		
		// en caso de ser null
		if( boletoSta == null || boletoSta.equals( "2" ) )
		{
			File f = new File( boletoDir ) ;
			return f.getAbsolutePath( ) ;
//			return formsDir ;
		}
		else
		{			
                        File f = new File( WEB_INF_DIR.replaceAll( "build\\\\web" , "WebContent" ) , boletoDir ) ;
			return f.getAbsolutePath( ) ;
//                        return "/WEB-INF/" + bcDir;
//			return WEB_INF_DIR + System.getProperty( "file.separator" ) + formsDir ;
		}
	}
                
        public static String getAgendaDir( )
	{
		String agendaDir = getConfProperty( CONF_PROPS_AGENDA_DIR_PATH ) ;
		String agendaSta = getConfProperty( CONF_PROPS_AGENDA_DIR_INSIDE ) ;
		
		// en caso de ser null
		if( agendaSta == null || agendaSta.equals( "2" ) )
		{
			File f = new File( agendaDir ) ;
			return f.getAbsolutePath( ) ;
//			return formsDir ;
		}
		else
		{			
                        File f = new File( WEB_INF_DIR.replaceAll( "build\\\\web" , "WebContent" ) , agendaDir ) ;
			return f.getAbsolutePath( ) ;
//                        return "/WEB-INF/" + bcDir;
//			return WEB_INF_DIR + System.getProperty( "file.separator" ) + formsDir ;
		}
	}
        
        public static String getCotizacionDir( )
	{
		String cotizacionDir = getConfProperty( CONF_PROPS_COTIZACION_DIR_PATH ) ;
		String cotizacionSta = getConfProperty( CONF_PROPS_COTIZACION_DIR_INSIDE ) ;
		
		// en caso de ser null
		if( cotizacionSta == null || cotizacionSta.equals( "2" ) )
		{
			File f = new File( cotizacionDir ) ;
			return f.getAbsolutePath( ) ;
//			return formsDir ;
		}
		else
		{			
                        File f = new File( WEB_INF_DIR.replaceAll( "build\\\\web" , "WebContent" ) , cotizacionDir ) ;
			return f.getAbsolutePath( ) ;
//                        return "/WEB-INF/" + bcDir;
//			return WEB_INF_DIR + System.getProperty( "file.separator" ) + formsDir ;
		}
	}
        
         public static String getMaterialDeAssetDir( )
	{
		String materialdeassetDir = getConfProperty( CONF_PROPS_MATERIALASSET_DIR_PATH ) ;
		String materialdeassetSta = getConfProperty( CONF_PROPS_MATERIALASSET_DIR_INSIDE ) ;
		
		// en caso de ser null
		if( materialdeassetSta == null || materialdeassetSta.equals( "2" ) )
		{
			File f = new File( materialdeassetDir ) ;
			return f.getAbsolutePath( ) ;
//			return formsDir ;
		}
		else
		{			
                        File f = new File( WEB_INF_DIR.replaceAll( "build\\\\web" , "WebContent" ) , materialdeassetDir ) ;
			return f.getAbsolutePath( ) ;
//                        return "/WEB-INF/" + bcDir;
//			return WEB_INF_DIR + System.getProperty( "file.separator" ) + formsDir ;
		}
	}
	
	public static String getFormsDirToDisplay( )
	{
		String formsDir = getConfProperty( CONF_PROPS_FORMS_DIR_PATH ) ;
		String formsSta = getConfProperty( CONF_PROPS_FORMS_DIR_INSIDE ) ;
		
		// en caso de ser null
		if( formsSta == null || formsSta.equals( "2" ) )
		{
			File f = new File( formsDir ) ;
			return f.getAbsolutePath( ) ;
		}
		else
			return "/WEB-INF/" + formsDir ;
	}
	
	public static void loadSystemProperties( Properties p )
	{
		try
		{
			FileInputStream in = new FileInputStream( MCUtil.WEB_INF_DIR + System.getProperty( "file.separator" ) + "system.properties" ) ;
			p.load( in ) ;
			in.close( ) ;
		}catch( Exception e )
		{
		}
	}
	
	public static String getConfProperty( String property )
	{
		try
		{
			FileInputStream in = new FileInputStream( MCUtil.WEB_INF_DIR + System.getProperty( "file.separator" ) + "system.properties" ) ;
			MCUtil.SYSTEM_PROPERTIES.load( in ) ;
			in.close( ) ;
			return MCUtil.SYSTEM_PROPERTIES.getProperty( property ) ;
		}catch( Exception e )
		{
			return null ;
		}
	}
        	
	public static String getTextFormated( UserLogin user , TblUsuario userSendingAlert , TblCuenta countSendingAlert , TblAsset asset , String texto , TblCampania campania )
	{
		if( userSendingAlert != null ){    
			texto = texto.replaceAll( "<nombre_usuario>" , userSendingAlert.getNombre( ) ) ;
                }else{
			texto = texto.replaceAll( "<nombre_usuario>" , "" ) ;
                }
                
		if( user != null ){
			texto = texto.replaceAll( "<nombre_usuario_genera>" , user.getUserName( ) ) ;
			texto = texto.replaceAll( "<Count_Name>" , campania.getTblCuenta().getNombre() ) ;
		}else{
                        texto = texto.replaceAll( "<nombre_usuario_genera>" , "" ) ;
			texto = texto.replaceAll( "<Count_Name>" , "" ) ;
                }
		
		if( countSendingAlert != null ){
                    texto = texto.replaceAll( "<Count_Name_Origin>" , countSendingAlert.getNombre( ) ) ;
                }else{
                    texto = texto.replaceAll( "<Count_Name_Origin>" , "" ) ;
                }	
		
		if( asset != null ){
			texto = texto.replaceAll( "<Asset_Name>" , asset.getNombre( ) ) ;
                }else{
			texto = texto.replaceAll( "<Asset_Name>" , "" ) ;
                }
                
                if ( campania != null ){
                    texto = texto.replaceAll( "<Campaign_Name>" , campania.getNombre() ) ;
                }else{
                    texto = texto.replaceAll( "<Campaign_Name>" , "" ) ;
                }
                
		texto = texto.replaceAll("Ã±", "ñ") ;
                texto = texto.replaceAll("Ã³", "ó") ;
                texto = texto.replaceAll("Ã­", "í") ;
                texto = texto.replaceAll("Ãº", "ú") ;
                texto = texto.replaceAll("Ã¡", "á") ;
                return texto ;
	}
	
	public static String getTextFormated( UserLogin user , TblUsuario userSendingAlert , TblCuenta countSendingAlert , TblTarea tarea , TblAsset asset , String texto )
	{
		if( tarea != null )
			texto = texto.replaceAll( "<nombre_tarea>" , tarea.getNombre( ) ) ;
		if( userSendingAlert != null )
			texto = texto.replaceAll( "<nombre_usuario>" , userSendingAlert.getNombre( ) ) ;
		if( user != null )
		{
			texto = texto.replaceAll( "<nombre_usuario_genera>" , user.getUserName( ) ) ;
			texto = texto.replaceAll( "<nombre_cuenta_genera>" , user.getActualCountName( ) ) ;
		}
		
		if( countSendingAlert != null )
			texto = texto.replaceAll( "<nombre_cuenta>" , countSendingAlert.getNombre( ) ) ;
		
		if( asset != null )
			texto = texto.replaceAll( "<nombre_asset>" , asset.getNombre( ) ) ;
		
		texto = texto.replaceAll("Ã±", "ñ") ;
                texto = texto.replaceAll("Ã³", "ó") ;
                texto = texto.replaceAll("Ã­", "í") ;
                texto = texto.replaceAll("Ãº", "ú") ;
                texto = texto.replaceAll("Ã¡", "á") ;
                return texto ;
	}
	
	public static String getTextFormated( UserLogin user , TblCampania campania , TblUsuario userSendingAlert , TblCuenta countSendingAlert , TblTarea tarea , TblAsset asset , String texto )
	{
		if( tarea != null )
			texto = texto.replaceAll( "<nombre_tarea>" , tarea.getNombre( ) ) ;
		if( userSendingAlert != null )
			texto = texto.replaceAll( "<nombre_usuario>" , userSendingAlert.getNombre( ) ) ;
		if( user != null )
		{
			texto = texto.replaceAll( "<nombre_usuario_genera>" , user.getUserName( ) ) ;
			texto = texto.replaceAll( "<nombre_cuenta_genera>" , user.getActualCountName( ) ) ;
		}
		
		if( countSendingAlert != null )
			texto = texto.replaceAll( "<nombre_cuenta>" , countSendingAlert.getNombre( ) ) ;
		
		if( asset != null )
			texto = texto.replaceAll( "<nombre_asset>" , asset.getNombre( ) ) ;
		
                texto = texto.replaceAll("Ã±", "ñ") ;
                texto = texto.replaceAll("Ã³", "ó") ;
                texto = texto.replaceAll("Ã­", "í") ;
                texto = texto.replaceAll("Ãº", "ú") ;
                texto = texto.replaceAll("Ã¡", "á") ;
		return texto ;
	}
        
        public static void sendMail( String mail , String subject , String message )
		throws
			MasterCardException
	{
		// en caso de que mail sea vacio
		if( mail == null || mail.trim( ).length( ) == 0 )
			return ;
                
                message = message.replaceAll("Ã±", "ñ") ;
                message = message.replaceAll("Ã³", "ó") ;
                message = message.replaceAll("Ã­", "í") ;
                message = message.replaceAll("Ãº", "ú") ;
                message = message.replaceAll("Ã¡", "á") ;
                
                message = message + "\n \naccede a tu cuenta en http://mastercard.codice.com/MasterCard/" ;
                
                subject = subject.replaceAll("Ã±", "ñ") ;
                subject = subject.replaceAll("Ã³", "ó") ;
                subject = subject.replaceAll("Ã­", "í") ;
                subject = subject.replaceAll("Ãº", "ú") ;
                subject = subject.replaceAll("Ã¡", "á") ;
		
		System.out.println( "Envia correo al " + mail + " subject: " + subject + " message: " + message ) ;
		
		try
		{
//			System.out.println( "__________ INICIA ENVIO CORREO ____________" ) ;
			Properties p = new Properties( ) ;
//			System.out.println( "__________ INICIA ENVIO CORREO 1 ____________" ) ;
			
			loadSystemProperties( p ) ;
			
//			System.out.println( "__________ INICIA ENVIO CORREO 2 ____________" ) ;
			Authenticator authenticator = new Authenticator();
			Session session = Session.getDefaultInstance( p , authenticator );
//			System.out.println( "__________ INICIA ENVIO CORREO 3 ____________" ) ;
//			String encodingOptions = "text/html; charset=ISO-8859-1";
			MimeMessage mess = new MimeMessage( session );
//			System.out.println( "__________ INICIA ENVIO CORREO 4 ____________" ) ;
//                        mess.setHeader("Content-Type", encodingOptions);
//			System.out.println( "__________ ENVIO CORREO ____________" ) ;
//			System.out.println( "__________ From: mastercardweb@mastercard.com ____________" ) ;
//			System.out.println( "__________ TO: " + mail + " ____________" ) ;
//			System.out.println( "__________ SUBJECT: " + subject + " ____________" ) ;
//			System.out.println( "__________ TEXT: " + message + " ____________" ) ;
			
			InternetAddress from = new InternetAddress( "confirmacionespricelessmusic@mastercard.com" ) ;
			mess.setFrom( from ) ;
			
			InternetAddress to = new InternetAddress( mail ) ;
			mess.addRecipient(
					Message.RecipientType.TO, to ) ;
			mess.setSubject( subject );
			mess.setText( message ) ;
			Transport.send( mess );
			
//			System.out.println( "__________ YA ENVIO ____________" ) ;
			// termina de enviar correo.
		}catch( Throwable e )
		{
			e.printStackTrace( ) ;
			throw new MasterCardException( 
					MCUtil.messages.getString( "com.mastercard.assets.web.modules.campania.errors.ErrorSendingMail" , e.getMessage( ) ) , 
					MCUtil.MASTERCARD_ERROR_CODE_SEND_MAIL , 
					e ) ;
		}
		
		
		////////////////
	}
        
        public static void sendMailForNotification( String mail , String subject , String message )
		throws
			MasterCardException
	{
		// en caso de que mail sea vacio
		if( mail == null || mail.trim( ).length( ) == 0 )
			return ;
		
                message = message.replaceAll("Ã±", "ñ") ;
                message = message.replaceAll("Ã³", "ó") ;
                message = message.replaceAll("Ã­", "í") ;
                message = message.replaceAll("Ãº", "ú") ;
                message = message.replaceAll("Ã¡", "á") ;
                
                message = message + "\n \naccede a tu cuenta en http://mastercard.codice.com/MasterCard/" ;
                
		System.out.println( "Envia correo al " + mail + " subject: " + subject + " message: " + message ) ;
                
                subject = subject.replaceAll("Ã±", "ñ") ;
                subject = subject.replaceAll("Ã³", "ó") ;
                subject = subject.replaceAll("Ã­", "í") ;
                subject = subject.replaceAll("Ãº", "ú") ;
                subject = subject.replaceAll("Ã¡", "á") ;
		
		try
		{
			Properties p = new Properties( ) ;			
			loadSystemProperties( p ) ;
			Authenticator authenticator = new Authenticator();
			Session session = Session.getDefaultInstance( p , authenticator );
			MimeMessage mess = new MimeMessage( session );			
			InternetAddress from = new InternetAddress( "confirmacionespricelessmusic@mastercard.com" ) ;
			mess.setFrom( from ) ;			
			InternetAddress to = new InternetAddress( mail ) ;
			mess.addRecipient( Message.RecipientType.TO, to ) ;
			mess.setSubject( subject );
			mess.setText( message ) ;
			Transport.send( mess );
			
		}catch( Throwable e )
		{
			e.printStackTrace( ) ;
			
		}
		
		
		////////////////
	}
        
        public static void sendMailGanador( String mail , String subject , String message )
		throws
			Exception
	{
		// en caso de que mail sea vacio
		if( mail == null || mail.trim( ).length( ) == 0 )
			return ;
		
                message = message.replaceAll("Ã±", "ñ") ;
                message = message.replaceAll("Ã³", "ó") ;
                message = message.replaceAll("Ã­", "í") ;
                message = message.replaceAll("Ãº", "ú") ;
                message = message.replaceAll("Ã¡", "á") ;
                
		System.out.println( "Envia correo al " + mail + " subject: " + subject + " message: " + message ) ;
                
                subject = subject.replaceAll("Ã±", "ñ") ;
                subject = subject.replaceAll("Ã³", "ó") ;
                subject = subject.replaceAll("Ã­", "í") ;
                subject = subject.replaceAll("Ãº", "ú") ;
                subject = subject.replaceAll("Ã¡", "á") ;
		
		try
		{
//			System.out.println( "__________ INICIA ENVIO CORREO ____________" ) ;
			Properties p = new Properties( ) ;
//			System.out.println( "__________ INICIA ENVIO CORREO 1 ____________" ) ;
			
			loadSystemProperties( p ) ;
			
//			System.out.println( "__________ INICIA ENVIO CORREO 2 ____________" ) ;
			Authenticator authenticator = new Authenticator();
			Session session = Session.getDefaultInstance( p , authenticator );
//			System.out.println( "__________ INICIA ENVIO CORREO 3 ____________" ) ;
			
			MimeMessage mess = new MimeMessage( session );
//			System.out.println( "__________ INICIA ENVIO CORREO 4 ____________" ) ;
//			
//			System.out.println( "__________ ENVIO CORREO ____________" ) ;
//			System.out.println( "__________ From: mastercardweb@mastercard.com ____________" ) ;
//			System.out.println( "__________ TO: " + mail + " ____________" ) ;
//			System.out.println( "__________ SUBJECT: " + subject + " ____________" ) ;
//			System.out.println( "__________ TEXT: " + message + " ____________" ) ;
			
			InternetAddress from = new InternetAddress( "mastercardweb@mastercard.com" ) ;
			mess.setFrom( from ) ;
			
			InternetAddress to = new InternetAddress( mail ) ;
			mess.addRecipient(
					Message.RecipientType.TO, to ) ;
			mess.setSubject( subject );
			mess.setText( message );
			Transport.send( mess );
			
//			System.out.println( "__________ YA ENVIO ____________" ) ;
			// termina de enviar correo.
		}catch( Exception e )
		{
			e.printStackTrace( ) ;
		}
		
		
		////////////////
	}
        
	public static void dropAllBCOfCampania( String path , int cveCampania )
	{
		File f = new File( path ) ;
		
		// toma todos los archivos
		File[ ] fs = f.listFiles( ) ;
		
		// recorre
		for( File fa : fs )
			// en csao e que sea del bussinescase
			if( fa.getName( ).startsWith( "BusinessCase-" + cveCampania + "." ) )
				fa.delete( ) ;
	}
	
	
	
	public static String savePreimplementacionPRFile( int cvePreimplementacionCotiza , String fileName , byte[ ] fileData )
		throws
			MasterCardException
	{
		// directorio
		String dir = MCUtil.getFormsDir( ) ;
		
		// nombre del arvhico
		String name = "PreimplementacionCotiza-PR-" + cvePreimplementacionCotiza + "-" + fileName ;
		
		// abre el directorio
		File dirFile = new File( dir ) ;
		
		// borra primero todos los que se encuentran de dicha cvePreimplementacionCotiza
		File[ ] list = dirFile.listFiles( ) ;
		
		for( File l : list )
		{
			// en caso de que empiecen con el nombre
			if( l.getName( ).startsWith( "PreimplementacionCotiza-PR-" + cvePreimplementacionCotiza ) )
				l.delete( ) ;
		}
		
		// abre el archivo
		File fileFile = new File( dirFile , name ) ;
		
		try
		{
			// abre stream de datos
			FileOutputStream out = new FileOutputStream( fileFile ) ;
			
			// guarda datos
			out.write( fileData ) ;
			
			// cierra
			out.close( ) ;
		}catch( Exception e )
		{
			e.printStackTrace( ) ;
			throw new MasterCardException( 
					MCUtil.messages.getString( "com.mastercard.assets.web.errors.modules.flows.display.WorkFlowWorkFormErrorProcessingData.preimplementacion.ErrorSavingFile" , e.getMessage( ) ) , 
					MCUtil.MASTERCARD_ERROR_CODE_FLOWS_PROCESS_PREIMPLEMENTATION_ERROR_SAVING_FILE , 
					e ) ;
		}
		
		return name ;
	}
	
	public static String savePreimplementacionPrimerFacturaFile( int cvePreimplementacionCotiza , String fileName , byte[ ] fileData )
		throws
			MasterCardException
	{
		// directorio
		String dir = MCUtil.getFormsDir( ) ;
		
		// nombre del arvhico
		String name = "PreimplementacionCotiza-PrimerFactura-" + cvePreimplementacionCotiza + "-" + fileName ;
		
		// abre el directorio
		File dirFile = new File( dir ) ;
		
		// borra primero todos los que se encuentran de dicha cvePreimplementacionCotiza
		File[ ] list = dirFile.listFiles( ) ;
		
		for( File l : list )
		{
			// en caso de que empiecen con el nombre
			if( l.getName( ).startsWith( "PreimplementacionCotiza-PrimerFactura-" + cvePreimplementacionCotiza ) )
				l.delete( ) ;
		}
		
		// abre el archivo
		File fileFile = new File( dirFile , name ) ;
		
		try
		{
			// abre stream de datos
			FileOutputStream out = new FileOutputStream( fileFile ) ;
			
			// guarda datos
			out.write( fileData ) ;
			
			// cierra
			out.close( ) ;
		}catch( Exception e )
		{
			e.printStackTrace( ) ;
			throw new MasterCardException( 
					MCUtil.messages.getString( "com.mastercard.assets.web.errors.modules.flows.display.WorkFlowWorkFormErrorProcessingData.preimplementacion.ErrorSavingFile" , e.getMessage( ) ) , 
					MCUtil.MASTERCARD_ERROR_CODE_FLOWS_PROCESS_PREIMPLEMENTATION_ERROR_SAVING_FILE , 
					e ) ;
		}
		
		return name ;
	}
	
	public static String savePreimplementacionAgendaFile( int cvePreimplementacionCotiza , String fileName , byte[ ] fileData )
		throws
			MasterCardException
	{
		// directorio
		String dir = MCUtil.getFormsDir( ) ;
		
		// nombre del arvhico
		String name = "PreimplementacionCotiza-Agenda-" + cvePreimplementacionCotiza + "-" + fileName ;
		
		// abre el directorio
		File dirFile = new File( dir ) ;
		
		// borra primero todos los que se encuentran de dicha cvePreimplementacionCotiza
		File[ ] list = dirFile.listFiles( ) ;
		
		for( File l : list )
		{
			// en caso de que empiecen con el nombre
			if( l.getName( ).startsWith( "PreimplementacionCotiza-Agenda-" + cvePreimplementacionCotiza ) )
				l.delete( ) ;
		}
		
		// abre el archivo
		File fileFile = new File( dirFile , name ) ;
		
		try
		{
			// abre stream de datos
			FileOutputStream out = new FileOutputStream( fileFile ) ;
			
			// guarda datos
			out.write( fileData ) ;
			
			// cierra
			out.close( ) ;
		}catch( Exception e )
		{
			e.printStackTrace( ) ;
			throw new MasterCardException( 
					MCUtil.messages.getString( "com.mastercard.assets.web.errors.modules.flows.display.WorkFlowWorkFormErrorProcessingData.preimplementacion.ErrorSavingFile" , e.getMessage( ) ) , 
					MCUtil.MASTERCARD_ERROR_CODE_FLOWS_PROCESS_PREIMPLEMENTATION_ERROR_SAVING_FILE , 
					e ) ;
		}
		
		return name ;
	}
	
	public static String savePreimplementacionContratoFile( int cvePreimplementacionCotiza , String fileName , byte[ ] fileData )
		throws
			MasterCardException
	{
		// directorio
		String dir = MCUtil.getFormsDir( ) ;
		
		// nombre del arvhico
		String name = "PreimplementacionCotiza-Contrato-" + cvePreimplementacionCotiza + "-" + fileName ;
		
		// abre el directorio
		File dirFile = new File( dir ) ;
		
		// borra primero todos los que se encuentran de dicha cvePreimplementacionCotiza
		File[ ] list = dirFile.listFiles( ) ;
		
		for( File l : list )
		{
			// en caso de que empiecen con el nombre
			if( l.getName( ).startsWith( "PreimplementacionCotiza-Contrato-" + cvePreimplementacionCotiza ) )
				l.delete( ) ;
		}
		
		// abre el archivo
		File fileFile = new File( dirFile , name ) ;
		
		try
		{
			// abre stream de datos
			FileOutputStream out = new FileOutputStream( fileFile ) ;
			
			// guarda datos
			out.write( fileData ) ;
			
			// cierra
			out.close( ) ;
		}catch( Exception e )
		{
			e.printStackTrace( ) ;
			throw new MasterCardException( 
					MCUtil.messages.getString( "com.mastercard.assets.web.errors.modules.flows.display.WorkFlowWorkFormErrorProcessingData.preimplementacion.ErrorSavingFile" , e.getMessage( ) ) , 
					MCUtil.MASTERCARD_ERROR_CODE_FLOWS_PROCESS_PREIMPLEMENTATION_ERROR_SAVING_FILE , 
					e ) ;
		}
		
		return name ;
	}
	
	public static String savePreimplementacionPOFile( int cvePreimplementacionCotiza , String fileName , byte[ ] fileData )
		throws
			MasterCardException
	{
		// directorio
		String dir = MCUtil.getFormsDir( ) ;
		
		// nombre del arvhico
		String name = "PreimplementacionCotiza-PO-" + cvePreimplementacionCotiza + "-" + fileName ;
		
		// abre el directorio
		File dirFile = new File( dir ) ;
		
		// borra primero todos los que se encuentran de dicha cvePreimplementacionCotiza
		File[ ] list = dirFile.listFiles( ) ;
		
		for( File l : list )
		{
			// en caso de que empiecen con el nombre
			if( l.getName( ).startsWith( "PreimplementacionCotiza-PO-" + cvePreimplementacionCotiza ) )
				l.delete( ) ;
		}
		
		// abre el archivo
		File fileFile = new File( dirFile , name ) ;
		
		try
		{
			// abre stream de datos
			FileOutputStream out = new FileOutputStream( fileFile ) ;
			
			// guarda datos
			out.write( fileData ) ;
			
			// cierra
			out.close( ) ;
		}catch( Exception e )
		{
			e.printStackTrace( ) ;
			throw new MasterCardException( 
					MCUtil.messages.getString( "com.mastercard.assets.web.errors.modules.flows.display.WorkFlowWorkFormErrorProcessingData.preimplementacion.ErrorSavingFile" , e.getMessage( ) ) , 
					MCUtil.MASTERCARD_ERROR_CODE_FLOWS_PROCESS_PREIMPLEMENTATION_ERROR_SAVING_FILE , 
					e ) ;
		}
		
		return name ;
	}
	
	public static String savePreimplementacionCotizaFile( int cvePreimplementacionCotiza , String fileName , byte[ ] fileData )
		throws
			MasterCardException
	{
		// directorio
		String dir = MCUtil.getFormsDir( ) ;
		
		// nombre del arvhico
		String name = "PreimplementacionCotiza-" + cvePreimplementacionCotiza + "-" + fileName ;
		
		// abre el directorio
		File dirFile = new File( dir ) ;
		
		// borra primero todos los que se encuentran de dicha cvePreimplementacionCotiza
		File[ ] list = dirFile.listFiles( ) ;
		
		for( File l : list )
		{
			// en caso de que empiecen con el nombre
			if( l.getName( ).startsWith( "PreimplementacionCotiza-" + cvePreimplementacionCotiza ) )
				l.delete( ) ;
		}
		
		// abre el archivo
		File fileFile = new File( dirFile , name ) ;
		
		try
		{
			// abre stream de datos
			FileOutputStream out = new FileOutputStream( fileFile ) ;
			
			// guarda datos
			out.write( fileData ) ;
			
			// cierra
			out.close( ) ;
		}catch( Exception e )
		{
			e.printStackTrace( ) ;
			throw new MasterCardException( 
					MCUtil.messages.getString( "com.mastercard.assets.web.errors.modules.flows.display.WorkFlowWorkFormErrorProcessingData.preimplementacion.ErrorSavingFile" , e.getMessage( ) ) , 
					MCUtil.MASTERCARD_ERROR_CODE_FLOWS_PROCESS_PREIMPLEMENTATION_ERROR_SAVING_FILE , 
					e ) ;
		}
		
		return name ;
	}
	
	// regresa los salvados
	public static List< String > saveAllCampaignSendedFiles( List< FormFile > archivos , int cveCampania , int cveEjecucionMaterial )
		throws
			MasterCardException
	{
		// archivos ya guardados
		List< String > archivosGuardados = new ArrayList< String >( ) ;
		
		String baseName = "Campania-" + cveCampania ;
		
		int index = 1 ;
		
		String dir = MCUtil.getFormsDir( ) ;
		
		// abre el directorio
		File dirFile = new File( dir ) ;
		
		// borra todos primero
		dropAllCampaignSendedFiles( cveCampania , cveEjecucionMaterial ) ;
		
		// recorre
		for( FormFile file : archivos )
		{
			// nombre
			String name = baseName + "-" + cveEjecucionMaterial + "-Sended-" + index + "-" + file.getFileName( ) ;
			
			try
			{
				// abre
				FileOutputStream out = new FileOutputStream( new File( dirFile , name ) ) ;
				
				out.write( file.getFileData( ) ) ;
				
				// cierra
				out.close( ) ;
				
				// guarda en guardados
				archivosGuardados.add( name ) ;
			}catch( Exception e )
			{
				// en caso d que falle
				// recorre guardados
				for( String s : archivosGuardados )
				{
					// borra
					File d = new File( dirFile , s ) ;
					
					// borra
					d.delete( ) ;
				}
				
				throw new MasterCardException( 
						MCUtil.messages.getString( "com.mastercard.assets.web.errors.modules.flows.display.WorkFlowWorkFormErrorProcessingData.campaign.ErrorSavingFiles" , e.getMessage( ) ) , 
						MCUtil.MASTERCARD_ERROR_CODE_FLOWS_PROCESS_CAMPAIGN_ERROR_SAVING_FILES , 
						e );
			}
			
			index++ ;
		}
		
		return archivosGuardados ;
	}
	
	// regresa los salvados
	public static List< String > saveAllCampaignReturnedFiles( List< FormFile > archivos , int cveCampania , int cveEjecucionMaterial )
		throws
			MasterCardException
	{
		// archivos ya guardados
		List< String > archivosGuardados = new ArrayList< String >( ) ;
		
		String baseName = "Campania-" + cveCampania ;
		
		int index = 1 ;
		
		String dir = MCUtil.getFormsDir( ) ;
		
		// abre el directorio
		File dirFile = new File( dir ) ;
		
		// borra todos primero
		dropAllCampaignReturnedFiles( cveCampania , cveEjecucionMaterial ) ;
		
		// recorre
		for( FormFile file : archivos )
		{
			// nombre
			String name = baseName + "-" + cveEjecucionMaterial + "-Returned-" + index + "-" + file.getFileName( ) ;
			
			try
			{
				// abre
				FileOutputStream out = new FileOutputStream( new File( dirFile , name ) ) ;
				
				out.write( file.getFileData( ) ) ;
				
				// cierra
				out.close( ) ;
				
				// guarda en guardados
				archivosGuardados.add( name ) ;
			}catch( Exception e )
			{
				// en caso d que falle
				// recorre guardados
				for( String s : archivosGuardados )
				{
					// borra
					File d = new File( dirFile , s ) ;
					
					// borra
					d.delete( ) ;
				}
				
				throw new MasterCardException( 
						MCUtil.messages.getString( "com.mastercard.assets.web.errors.modules.flows.display.WorkFlowWorkFormErrorProcessingData.campaign.ErrorSavingFiles" , e.getMessage( ) ) , 
						MCUtil.MASTERCARD_ERROR_CODE_FLOWS_PROCESS_CAMPAIGN_ERROR_SAVING_FILES , 
						e );
			}
			
			index++ ;
		}
		
		return archivosGuardados ;
	}

	public static String saveCampaignReturnedFiles( FormFile archivo , int cveCampania , int cveEjecucionMaterial )
		throws
			MasterCardException
	{
		// archivos ya guardados
		String archivosGuardado = "" ;
		
		String baseName = "Campania-" + cveCampania ;
		
		int index = 1 ;
		
		String dir = MCUtil.getFormsDir( ) ;
		
		// abre el directorio
		File dirFile = new File( dir ) ;
		
		// borra todos primero
		dropAllCampaignReturnedFiles( cveCampania , cveEjecucionMaterial ) ;
		
		// nombre
		String name = baseName + "-" + cveEjecucionMaterial + "-Returned-" + index + "-" + archivo.getFileName( ) ;
		
		try
		{
			// abre
			FileOutputStream out = new FileOutputStream( new File( dirFile , name ) ) ;
			
			out.write( archivo.getFileData( ) ) ;
			
			// cierra
			out.close( ) ;
			
			// guarda en guardados
			archivosGuardado = name ;
		}catch( Exception e )
		{
			throw new MasterCardException( 
					MCUtil.messages.getString( "com.mastercard.assets.web.errors.modules.flows.display.WorkFlowWorkFormErrorProcessingData.campaign.ErrorSavingFiles" , e.getMessage( ) ) , 
					MCUtil.MASTERCARD_ERROR_CODE_FLOWS_PROCESS_CAMPAIGN_ERROR_SAVING_FILES , 
					e );
		}
		
		return archivosGuardado ;
	}

	public static String saveCampaignWinners( FormFile archivo , int cveCampania , int cveEjecucionMaterial )
		throws
			MasterCardException
	{
		// archivos ya guardados
		String archivosGuardado = "" ;
		
		String baseName = "Campania-" + cveCampania ;
		
		int index = 1 ;
		
		String dir = MCUtil.getFormsDir( ) ;
		
		// abre el directorio
		File dirFile = new File( dir ) ;
		
		// borra todos primero
		dropAllCampaignWinners( cveCampania , cveEjecucionMaterial ) ;
		
		// nombre
		String name = baseName + "-" + cveEjecucionMaterial + "-Winners-" + index + "-" + archivo.getFileName( ) ;
		
		try
		{
			// abre
			FileOutputStream out = new FileOutputStream( new File( dirFile , name ) ) ;
			
			out.write( archivo.getFileData( ) ) ;
			
			// cierra
			out.close( ) ;
			
			// guarda en guardados
			archivosGuardado = name ;
		}catch( Exception e )
		{
			throw new MasterCardException( 
					MCUtil.messages.getString( "com.mastercard.assets.web.errors.modules.flows.display.WorkFlowWorkFormErrorProcessingData.campaign.ErrorSavingFiles" , e.getMessage( ) ) , 
					MCUtil.MASTERCARD_ERROR_CODE_FLOWS_PROCESS_CAMPAIGN_ERROR_SAVING_FILES , 
					e );
		}
		
		return archivosGuardado ;
	}

	public static void dropAllCampaignSendedFiles( int cveCampania , int cveEjecucionMaterial )
		throws
			MasterCardException
	{
		String dir = MCUtil.getFormsDir( ) ;
		
		File dirFile = new File( dir ) ;
		
		// archivos a borrar
		String[ ] archivosGuardados = dirFile.list( ) ;
		
		String baseName = "Campania-" + cveCampania + "-" + cveEjecucionMaterial + "-Sended-" ;
		
		// en caso d que falle
		// recorre guardados
		for( String s : archivosGuardados )
		{
			if( ! s.startsWith( baseName ) )
				continue ;
			
			// en caso d que no empiece con el nom bre base
			
			// borra
			File d = new File( dirFile , s ) ;
			
			// borra
			d.delete( ) ;
		}
	}

	public static void dropAllCampaignReturnedFiles( int cveCampania , int cveEjecucionMaterial )
		throws
			MasterCardException
	{
		String dir = MCUtil.getFormsDir( ) ;
		
		File dirFile = new File( dir ) ;
		
		// archivos a borrar
		String[ ] archivosGuardados = dirFile.list( ) ;
		
		String baseName = "Campania-" + cveCampania + "-" + cveEjecucionMaterial + "-Returned-" ;
		
		// en caso d que falle
		// recorre guardados
		for( String s : archivosGuardados )
		{
			if( ! s.startsWith( baseName ) )
				continue ;
			
			// en caso d que no empiece con el nom bre base
			
			// borra
			File d = new File( dirFile , s ) ;
			
			// borra
			d.delete( ) ;
		}
	}

	public static void dropAllCampaignWinners( int cveCampania , int cveEjecucionMaterial )
		throws
			MasterCardException
	{
		String dir = MCUtil.getFormsDir( ) ;
		
		File dirFile = new File( dir ) ;
		
		// archivos a borrar
		String[ ] archivosGuardados = dirFile.list( ) ;
		
		String baseName = "Campania-" + cveCampania + "-" + cveEjecucionMaterial + "-Winners-" ;
		
		// en caso d que falle
		// recorre guardados
		for( String s : archivosGuardados )
		{
			if( ! s.startsWith( baseName ) )
				continue ;
			
			// en caso d que no empiece con el nom bre base
			
			// borra
			File d = new File( dirFile , s ) ;
			
			// borra
			d.delete( ) ;
		}
	}

	public static void dropAllCampaignFiles( List< String > archivosGuardados )
		throws
			MasterCardException
	{
		String dir = MCUtil.getFormsDir( ) ;
		
		File dirFile = new File( dir ) ;
		
		// en caso d que falle
		// recorre guardados
		for( String s : archivosGuardados )
		{
			// borra
			File d = new File( dirFile , s ) ;
			
			// borra
			d.delete( ) ;
		}
	}
	
	public static int getFileNameIndex( String fileName )
	{
		if( fileName == null || fileName.trim( ).length( ) == 0 )
			return -1 ;
		
		// toma el indice del primer guion
		int index = fileName.indexOf( "-" ) ;
		
		// en caso de -1
		if( index == -1 )
			return -1 ;
		
		// en caso de no
		// segundo guion
		index = fileName.indexOf( "-" , index + 1 ) ;
		
		if( index == -1 )
			return -1 ;
		
		// en caso de no
		// tercer guion
		index = fileName.indexOf( "-" , index + 1 ) ;
		
		if( index == -1 )
			return -1 ;
		
		// en caso de no
		// cuarto guion
		index = fileName.indexOf( "-" , index + 1 ) ;
		
		if( index == -1 )
			return -1 ;
		
		// en caso de que si exista
		// quinto guion
		int indexFinal = fileName.indexOf( "-" , index + 1 ) ;
		
		if( indexFinal == -1 )
			return -1 ;
		
		// toma el string
		String indexString = fileName.substring( index + 1 , indexFinal ) ;
		
		// intenta convertirlo en entero
		try
		{
			return Integer.parseInt( indexString ) ;
		}catch( Exception e )
		{
			return -1 ;
		}
	}
	
	public static String getStaticTable( String text )
	{
		// en csao de vacio
		if( text == null || text.trim( ).length( ) == 0 )
			return "" ;
		
		// en caso de que no venga en null o vacio
		// separa en tokens por <br/><br/>
		String tokens[ ] = text.trim( ).split( "<br/><br/>" ) ;
		
		// construye el arreglo con los dos nombres, o uno en caso de que sea uno solo
		String[ ] names = null ;
		
		if( tokens.length == 1 )
		{
			names = new String[ 1 ] ;
			
			// toma los nombres
			// toma el primer token y lo separa en tokens
			String[ ] namesTokens = tokens[ 0 ].split( ":" ) ;
			
			// el primer token es el nombre
			names[ 0 ] = namesTokens[ 0 ] ;
		}
		// en caso d que haya mas de uno
		else
		{
			names = new String[ 2 ] ;
			
			// toma los nombres
			// toma el primer token y lo separa en tokens
			String[ ] namesTokens1 = tokens[ 0 ].split( ":" ) ;
			String[ ] namesTokens2 = tokens[ 1 ].split( ":" ) ;
			
			// el primer token es el nombre
			names[ 0 ] = namesTokens1[ 0 ] ;
			names[ 1 ] = namesTokens2[ 0 ] ;
		}
		
		// forma la tabla
		StringBuffer sb = new StringBuffer( ) ;
		// empieza la tabla
		sb.append( "<table border='0'>" ) ;
		sb.append( "<tr style='background: #E6E6E6;'>" ) ;
		// crea el renglon principal
		for( String name : names )
			sb.append( "<td style='text-align: center;'>" + name + "</td>" ) ;
		sb.append( "</tr>" ) ;
		
		// numero de renglon
		int ren = 0 ;
		
		// construye los otros renglones
		for( String token : tokens )
		{
			// divide el token en dos
			String[ ] subToken = token.split( ":" ) ;
			
			// en caso de que sea renglon par
			if( ( ren % 2 ) == 0 )
			{
				sb.append( "<tr>" ) ;
                                if( subToken.length > 1 ){
                                    sb.append( "<td style='text-align: center; background:#CCCCCC;'>" + subToken[ 1 ] + "</td>" ) ;
                                }else {
                                    sb.append( "<td style='text-align: center; background:#CCCCCC;'>&nbsp;</td>" ) ;
                                }
                                    
				if( names.length > 1 )
					sb.append( "<td style='text-align: center; background:#e6e6e6;'>&nbsp;</td>" ) ;
				sb.append( "</tr>" ) ;
			}
			// en caso de que sea impar
			else
			{
				sb.append( "<tr>" ) ;
				if( names.length > 1 )
                                    sb.append( "<td style='text-align: center; background:#e6e6e6;'>&nbsp;</td>" ) ;
                                if( subToken.length > 1 ){
                                    sb.append( "<td style='text-align: center; background:#83CAFF;'>" + subToken[ 1 ] + "</td>" ) ;
                                }else {
                                    sb.append( "<td style='text-align: center; background:#83CAFF;'>&nbsp;</td>" ) ;
                                }
                                
				sb.append( "</tr>" ) ;
			}
			
			// aumenta numero de renglon
			ren++ ;
		}
		
		sb.append( "</table>" ) ;
		
		String res = sb.toString( ) ;
		sb.setLength( 0 ) ;
		sb = null ;
		return res ;
	}
	
	public static String getParam( String paramName , HttpServletRequest request )
	{
		if( paramName == null || paramName.trim( ).length( ) == 0 || request == null )
			return "" ;
		
		String value = request.getParameter( paramName ) ;
		
		if( value == null )
			return "" ;
		
		return value ;
	}
        public static String TextoFormateado( String texto )
	{
            texto = texto.replaceAll("Ã±", "ñ") ;
            texto = texto.replaceAll("Ã³", "ó") ;
            texto = texto.replaceAll("Ã­", "í") ;
            texto = texto.replaceAll("Ãº", "ú") ;
            texto = texto.replaceAll("Ã¡", "á") ;
            texto = texto.replaceAll("Ã©", "é") ;
            
            return texto ;
	}
}

class Authenticator extends javax.mail.Authenticator {
		public PasswordAuthentication authentication;

		public Authenticator() {
			String username = "mastercard@codice.com";
			String password = "master##";
			authentication = new PasswordAuthentication(username, password);
		}
                
		public PasswordAuthentication getPasswordAuthentication() {
			return authentication;
		}
	}
